$(function () {
    $('#tab-bar').remove();
//        总共60秒  15秒发一次
    Magiclamp.mcProgress(600, '', '', function () {
    });

    if (sd_orderid > 0) {//有神灯订单才执行
        var send = setInterval(change_sd_status, 15000);
        var send_count = 4;
        change_sd_status();
    }
    function change_sd_status() {
        if (send_count > 0) {
            Magiclamp.mcAjax('/pay/main/getorderstatus/' + sd_orderid + "?" + send_count, 'POST', '', function (data) {
                if (data.status == 1) {
                    send_count = 0;
                    clearInterval(send);
                    var goodloker = data.data.goodloker;
                    var badloker = data.data.badloker;
                    if (goodloker.length > 0) {
                        goodloker.forEach(function (q) {
                            $("#d" + q).html('门已打开,请及时取货');
                        })
                    }
                    if (badloker.length > 0) {
                        badloker.forEach(function (q) {
                            $("#d" + q).html(errmsg);
                        })
                    }
                } else {
                    if (data.error_code == 1) {//订单未支付  不再执行查询
                        send_count = 0;
                        clearInterval(send);
                        $('.prs-bar').html(data.message);
                    } else if (send_count == 1) {//最后一次仍然没有获取到开门信息 给出错误！
                        $('.prs-bar').html(errmsg);
                    }
                }
                send_count = send_count - 1;
            }, function () {
                $('.prs-bar').html('开门出错！');
                Magiclamp.mcAlert('', '开门出错，请联系前台！');
                send_count = 0;
                clearInterval(send);
            })
        } else {
            clearInterval(send);
        }
    }

    if (dn_orderid > 0) {
        var dn_send = setInterval(change_dn_status, 5000);
        var dn_send_count = 200;
        change_dn_status();
    }
    function change_dn_status() {
        if (dn_send_count > 0) {
            Magiclamp.mcAjax('/pay/main/getdnorderstatus/' + dn_orderid + "?" + dn_send_count, 'POST', '',
                function (data) {
                    dn_send_count--;
                    if (data.status == 1) {
                        $('.dn-msg').html(data.message);
                        //停止查询
                        $('.dn-msg-before').remove();
                        dn_send_count = 0;
                        clearInterval(dn_send);
                    }
                    if (data.data.type_send == 2) {//已经送货的不再继续查询
                        //停止查询
                        $('.dn-msg-before').remove();
                        dn_send_count = 0;
                        clearInterval(dn_send);
                    }
                }, function () {
                    dn_send_count--; 
                })
        }
    }

});